package org.BUPT.infrastructure.persistent.DAO;

import org.BUPT.infrastructure.persistent.po.Like;
import org.BUPT.infrastructure.persistent.po.LikePrimaryKey;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface LikeDAO extends CrudRepository<Like, LikePrimaryKey> {
    @Query("select l from Like l " +
            "where l.likePrimaryKey.userId=:userId " +
            "and l.likePrimaryKey.answerId=:answerId")
    Like getLikeOfAnswerByUser(@Param("userId") int userId, @Param("answerId") int answerId);

    @Query("select l.likePrimaryKey.userId from Like l where l.likePrimaryKey.answerId=:answerId")
    List<Integer> getLikeCountOfAnswer(@Param("answerId") int answerId);
}
